<?php
 include "counter2.php";

pagestart();
print "<html>";
pagehead(_("Most Penguin-Friendly Place Competition"));

  $poplimit = $counter->get_input('poplimit', 'number', 'get|post');
  if (!$poplimit) {
      $poplimit = 1;
  }
  # the counter works with millions...
  $mlimit = $poplimit / 1000000;

print "\n<BODY bgcolor=\"white\">";
pagetop();
print "\n<table width=95%>" .
   "\n<tr>" .
       "\n<td><h1><img src=\"/gifs/Logo-small.png\" alt=\"" . _("Linux Counter Logo") . "\">" . _("Penguin Friendly Places") . "</h1></td>" .
       "\n<td align=\"right\">\n" .
       _("Places with more than:") .
       "\n<ul>" .
           "\n<li><a href=\"./citystat.php?poplimit=1000\">1000 " . _("people") . "</a>" .
           "\n<li><a href=\"./citystat.php?poplimit=10000\">10.000 " . _("people") . "</a>" .
           "\n<li><a href=\"./citystat.php?poplimit=100000\">100.000 " . _("people") . "</a>" .
           "\n<li><a href=\"./citystat.php?poplimit=1000000\">1.000.000 " . _("people") . "</a>" .
           "\n<li><a href=\"./citystat.php?poplimit=1\">" . _("No limit") . "</a>" .
       "\n</ul>" .
       "\n</td>" .
   "\n</tr>" .
"\n</table>\n";

print _("This page gives a list of the 100 places where Linux is the Most Used System!") .
"\n<p>\n" .
_("A place is entered here when:") .
"\n<ul>" .
    "\n<li>" . _("It has more than 5 Linux users") .
    "\n<li><a href=\"maintainers.php\">" . _("The country manager") . "</a> " . _("for that area has entered its population.") .
    "\n<li>" . _("The place has more than ") . $poplimit . ($poplimit > 1 ? " " . _("people") : " " . _("person")) .
"\n</ul>\n";

print _("At") . " <span id=\"gmtime\">" . gmstrftime ('%b %d %Y %H:%M:%S',time())."\n" . " " . _("GMT, the following cities/states/countries are in the lead:") . "\n<br>";

print "\n<table border>" .
   "\n<tr>" .
       "\n<th>#</th>" .
       "\n<th>" . _("Name") . "</th>" .
       "\n<th>" . _("Type") . "</th>" .
       "\n<th>" . _("Population") . "</th>" .
       "\n<th>" . _("Users") . "</th>" .
       "\n<th>" . _("Density") . "</th>" .
   "\n</tr>";

 $query = mysql_query("select p.longname, p.type, p.population, p.users, p.users/p.population as density, p.name, pp.longname, ppp.longname as ppplongname from places as p, places as pp left join places as ppp on (pp.within = ppp.f_key) where p.population > $mlimit and p.users > 5 and p.within = pp.f_key order by density desc limit 100");

 $index = 0;
 while ($arr = mysql_fetch_row($query)) {
    $index += 1;
    $recname = $arr[5];
    if ($arr[1] == 'country') {
        $printname = $arr[0];
    } elseif($arr[7] == 'The World' || $arr[7] == 'NULL') {
        $printname =  $arr[0] . ", " . $arr[6];
    } else {
        $printname = $arr[0] . ", " . $arr[6] . ", " . $arr[7] ;
    }

print "\n<tr>" .
       "\n<td>" . $index . "</td>" .
       "\n<td>" . place_page($recname, $printname) . "</td>" .
       "\n<td>" . $arr[1] . "</td>" .
       "\n<td align=\"right\">" . number_format($arr[2] * 1000000, 0, ".", " ") . "</td>" .
       "\n<td align=\"right\">" . $arr[3] . "</td>" .
       "\n<td align=\"right\">" . number_format($arr[4], 2) . "</td>" .
   "\n</tr>";
 }

print "\n</table>" .
"\n<h2><a href=\"/enter-person.php\">" . _("Get Counted!") . "</a></h2>\n";
pagebottom();
print "\n</body>\n</html>";
?>
